package com.dayilyword.controller;

import com.alibaba.fastjson.JSON;
import com.dayilyword.config.resultFormat.Result;
import com.dayilyword.config.resultFormat.ResultFormat;
import com.dayilyword.entity.SysUser;
import com.dayilyword.service.AttentionService;
import com.dayilyword.service.MsgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.crypto.RandomNumberGenerator;
import org.apache.shiro.crypto.SecureRandomNumberGenerator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * <p>>@作者 Sc
 * <p>>@所属包 dayilyword:com.dayilyword.controller
 * <p>>@创建时间 2020-11-13-12-46
 * <p>>@功能描述
 **/
@RestController
@RequestMapping("attention")
@Api(tags = "关注")
public class AttentionController {
    private final Logger logger = LoggerFactory.getLogger(AttentionController.class);

    @Autowired
    AttentionService attentionService;

    @PostMapping()
    @ApiOperation("关注")
    public Result attention(HttpServletRequest request,
                            @RequestParam("targetUserId") int targetUserId) {
        Integer userId = (Integer) request.getSession().getServletContext().getAttribute("userId");

        attentionService.attention(userId, targetUserId);
        return ResultFormat.ok("attention_IS_Success");
    }


    @DeleteMapping()
    @ApiOperation("取消关注")
    public Result disableMsgAttention(HttpServletRequest request,
                                      @RequestParam("targetUserId") int targetUserId) {
        Integer userId = (Integer) request.getSession().getServletContext().getAttribute("userId");

        attentionService.disableMsgAttention(userId, targetUserId);
        return ResultFormat.ok("delete_attention_IS_Success");
    }

    @GetMapping("/getAttentionList")
    @ApiOperation("获得关注列表")
    public Result getAttentionList(HttpServletRequest request) {

        Integer userId = (Integer) request.getSession().getServletContext().getAttribute("userId");

        return ResultFormat.ok(JSON.toJSONString(attentionService.getAttentionList(userId)));
    }

    @GetMapping("/getFansList")
    @ApiOperation("获得粉丝列表")
    public Result getFanslist(HttpServletRequest request) {
        Integer userId = (Integer) request.getSession().getServletContext().getAttribute("userId");

        return ResultFormat.ok(JSON.toJSONString(attentionService.getFansList(userId)));
    }
}
